<template>
  <div>
    <div class="loader"></div>
  </div>
</template>

<script>
  import axios from '../api/config'
  export default{
    mounted(){
      sessionStorage.setItem("parameter", JSON.stringify(this.$route.query))
      this.$vux.loading.show({
        text: '加载中...'
      })
      //需要检查是否把参数写入本地，否则会报错
      if(sessionStorage.getItem("parameter")){
        this.getStatus()
      }
      //console.log(this.$route.query)
      //写 sessionstoreage
      //读 sessionstoreage
      //sessionStorage.getItem("parameter")
      //"{"customer":"1","policyNo":"75D9BD53510B7630755EC17","waybillNo":"123456"}"
    },
    methods:{
      getStatus(){
        //判断运单时效（刚进入页面时候判断时效）
        //判断是否发起理赔（刚进入页面的时候判断）
        this.waybillNo = this.$route.query.waybillNo
        let url = `/claims/${this.waybillNo}/status`
        console.log(url)
        axios.get(url)
          .then(res => {
            console.log(res)
            this.$vux.loading.hide()
            if (res.data.data.claimStatus === 'NOT_EXIST') {
              console.log("未发理赔 => 协议说明")
              this.$router.replace({
                name: 'protocol',
                params: {waybillNo: this.waybillNo}
              })
            } else {
              console.log("发起理赔 => 进度页")
              console.log("运单=>"+this.waybillNo)
              this.$router.replace({
                name: 'progress',
                params: {waybillNo: this.waybillNo}
              })
            }
          })
          .catch(error => {
            console.log(error)
          })
      },
    }
  }
</script>
